//
//  HOMyReportViewController.m
//  微度报修
//
//  Created by foguo-mac-1 on 6/12/16.
//  Copyright © 2016 WeiDu. All rights reserved.
//

#import "HOMyReportViewController.h"
#import "HOReportEntity.h"
#import "HOUtils.h"
#import "UIImageView+WebCache.h"
#import "HOMyReportCell.h"
#import "HOReportOrderEntity.h"
#import "HOReportListTableViewCell.h"
#import "HOConstants.h"
#import "HOReportDetailViewController.h"
#import "HOButton.h"
#import "HOStaticDataMgr.h"
#import "HOViewStatusViewController.h"
#import "HORepaireDoneViewController.h"
#import "HOConfirmOrderViewController.h"
#import "NSString+Extension.h"

@interface HOMyReportViewController ()
{
	NSMutableDictionary *reportDic;
	UIView 				*statusSelectView;
	UILabel 			*statusLbl;
}
@property(nonatomic, retain)UIFont *contentFont;
@property(nonatomic, retain)NSString *companyId;
@end

@implementation HOMyReportViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
	[self initVaribles];
	[self initTableView];
//	[self initTestData];
	[self requestDataWithMaxId:1];
	[self initPickerView];
	if(self.isAssistantReport)
	{
		[self initStatusSelectView];
	}
	
}

- (void)initVaribles
{
	
	self.contentFont = [UIFont systemFontOfSize:13];;
	reportDic = [[NSMutableDictionary alloc] init];
}
- (void)initStatusSelectView
{
	statusSelectView = [[UIView alloc]
						initWithFrame:CGRectMake(0,
												 0,
												 self.view.frame.size.width,
												 44)];
	//	statusSelectView.layer.borderWidth = 1;
	[statusSelectView setBackgroundColor:[UIColor whiteColor]];
	NSString *title = [HOUtils getDescribtionWithStatus:self.currentStatus];

	
	UIButton *btn = [[UIButton alloc]
					 initWithFrame:CGRectMake(0,
											  0,
											  self.view.frame.size.width,
											  44)];
	btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
	
	//		[btn setTitle:title forState:UIControlStateNormal];
	[btn setBackgroundImage:[HOUtils createImageWithColor:UIColorFromRGB(0xf0f0f0) forView:btn] forState:UIControlStateNormal];
	[btn setTitleColor:TEXT_COLOR_181818 forState:UIControlStateNormal];
	[btn addTarget:self action:@selector(didChangeStatus:) forControlEvents:UIControlEventTouchUpInside];
	[statusSelectView addSubview:btn];
	[btn release];
	
	statusLbl = [[UILabel alloc]
				 initWithFrame:CGRectMake(HO_HORIZONAL_PADDING,
										  (44 - 22) / 2,
										  200,
										  22)];
	statusLbl.text = title;
	statusLbl.font = [UIFont systemFontOfSize:15];
	statusLbl.textColor = TEXT_COLOR_666666;
	[statusSelectView addSubview:statusLbl];
	
	UIImageView *imgView = [[UIImageView alloc]
							initWithFrame:CGRectMake(self.view.frame.size.width - 16 - HO_HORIZONAL_PADDING,
													 (44 - 9) / 2,
													 16,
													 9)];
	imgView.image = [UIImage imageNamed:@"ic_baoxiuliebiao_zhankai"];
	[statusSelectView addSubview:imgView];
	[imgView release];
	[self.view addSubview:statusSelectView];
	baseTableview.frame = CGRectMake(0,
									 statusSelectView.frame.size.height,
									 self.view.frame.size.width,
									 self.view.frame.size.height - statusSelectView.frame.size.height);
}


- (void)didChangeStatus:(id)sender
{
	[self showPickerView:YES];
}

#pragma mark
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
	[self showPickerView:NO];
	[self hideKeyboard];
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
	return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
//	NSArray *array = [HOUtils getReportOrderStatus];
//	return [array count];
	return 3;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
	if(row == 0)
	{
		return NSLocalizedString(@"已受理", @"已受理");
	}
	else if(row == 1)
	{
		return NSLocalizedString(@"维修完成", @"维修完成");
	}
	else
	{
		return NSLocalizedString(@"确认完成", @"确认完成");
	}
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
	pickerViewSelectRow = row;
}

- (void)didPickDone:(id)sender
{
	[super didPickDone:nil];
	if(pickerViewSelectRow == 0)
	{
		self.currentStatus = HO_REPORT_ORDER_ACCEPTED;
	}
	else if(pickerViewSelectRow == 1)
	{
		self.currentStatus = HO_REPORT_ORDER_REPAIRED;
	}
	else
	{
		self.currentStatus = HO_REPORT_ORDER_CONFIRMED;
	}
	
	statusLbl.text = [HOUtils getDescribtionWithStatus:self.currentStatus];
//	self.currentStatus = [[[HOUtils getReportOrderStatus] objectAtIndex:pickerViewSelectRow] intValue];
	[self requestDataWithMaxId:0];
}

- (void)requestDataWithMaxId:(int)maxId
{
	if(self.isAssistantReport)
	{
		if(self.isUnacceptReport)
		{
			//未受理的协助单
			[self sendRequestWithParams:@{kHO_FIELD_Action:kHO_ACTION_GetSelfAssistantOrderList,
										  kHO_FIELD_MaxID:[NSNumber numberWithInt:maxId],
										  kHO_FIELD_Status:[NSNumber numberWithInt:HO_REPORT_ORDER_UNACCEPT]}];
		}
		else
		{
			[self sendRequestWithParams:@{kHO_FIELD_Action:kHO_ACTION_GetSelfAssistantOrderList,
										  kHO_FIELD_MaxID:[NSNumber numberWithInt:maxId],
										  kHO_FIELD_Status:[NSNumber numberWithInt:self.currentStatus]}];
		}
	}
	else
	{
		if(self.currentStatus == HO_REPORT_ORDER_ALL)
		{
			[self sendRequestWithParams:@{kHO_FIELD_Action:kHO_ACTION_GetOrderList,
										  kHO_FIELD_MaxID:[NSNumber numberWithInt:maxId],
										  kHO_FIELD_Status:[NSNumber numberWithInt:self.currentStatus],
										  kHO_FIELD_DataType:[NSNumber numberWithInt:1]}];   //DataType数据类型[0全部数据 1个人数据]
		}
		else
		{
			[self sendRequestWithParams:@{kHO_FIELD_Action:kHO_ACTION_GetOrderList,
										  kHO_FIELD_MaxID:[NSNumber numberWithInt:maxId],
										  kHO_FIELD_Status:[NSNumber numberWithInt:self.currentStatus],
										  kHO_FIELD_DataType:[NSNumber numberWithInt:2]}];
		}
	}

	
}

- (void)pullUpToRefresh
{
	HOReportOrderEntity *entity = [self.tableViewDataList lastObject];
	if(entity)
	{
		[self requestDataWithMaxId:entity.orderId];
	}
	else
	{
		[self requestDataWithMaxId:1];
	}
}

- (void)pullDownToRefresh
{
	[self requestDataWithMaxId:1];
}

- (void)viewWillAppear:(BOOL)animated
{
	self.tabBarController.tabBar.hidden = YES;
	[super viewWillAppear:animated];
	[self setNavigationItemTitle:self.navTitle];
	[self requestDataWithMaxId:1];
	if(self.isAssistantReport)
	{
		if(self.isUnacceptReport)
		{
			pickerPanelView.hidden = YES;
			statusSelectView.hidden = YES;
			baseTableview.frame = CGRectMake(0,
											 0,
											 self.view.frame.size.width,
											 [HOUtils getScreenHeight] - [HOUtils getStatusBarHeight] - 47 - 0);
		}
		else
		{
			baseTableview.frame = CGRectMake(0,
											 statusSelectView.frame.size.height,
											 self.view.frame.size.width,
											 [HOUtils getScreenHeight] - [HOUtils getStatusBarHeight] - 47 - statusSelectView.frame.size.height );
		}
		
	}
	else
	{
		baseTableview.frame = CGRectMake(baseTableview.frame.origin.x,
										 baseTableview.frame.origin.y,
										 baseTableview.frame.size.width,
										  ([HOUtils getScreenHeight] - 44 - [HOUtils getStatusBarHeight]));
	}
}

- (void)viewDidAppear:(BOOL)animated
{
	[super viewDidAppear:animated];
}

- (void)rightButtonItemDidClick
{
	[self showPickerView:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - -- UITableViewDelegate/UITableViewDataResource implement methods
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
	if(indexPath.row == 0)
	{
		HOReportOrderEntity *entity = [self.tableViewDataList objectAtIndex:indexPath.section];

		CGFloat width = tableView.frame.size.width - 78.0f;
		NSString *address = [NSString stringWithFormat:@"故障位置:%@", [HOUtils getValideString:entity.address]];
		CGSize addressSize = [address sizeWithFont:self.contentFont maxW:width];
		NSString *content = [NSString stringWithFormat:@"故障描述:%@", [entity getFaultDetailContent]];
		CGSize contentSize = [content sizeWithFont:[UIFont systemFontOfSize:14] maxW:width];
		CGFloat height = 26 + 26 + 4 + 8 + MAX(addressSize.height, 20) +  MAX(contentSize.height, 20) + 8;
		return height;
		
	}
	else if(indexPath.row == 1)
	{
		return 44;
	}
	return 0;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
	NSInteger count = [self.tableViewDataList count];
	[self updateNoResultView:count];;
    return count;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	if(self.isAssistantReport)
		return 2;
    return 2;
}


- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return HO_HORIZONAL_PADDING / 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	HOReportOrderEntity *entity = [self.tableViewDataList objectAtIndex:indexPath.section];
	
	if(indexPath.row == 0)
	{
		static NSString *ReportTableViewCellIdentifier = @"ReportTableViewCellIdentifier2";
		UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:ReportTableViewCellIdentifier];
		if(cell == nil)
		{
			cell = [[[UITableViewCell alloc]init] autorelease];
			cell.selectionStyle = UITableViewCellSelectionStyleGray;
		}
		cell.selectionStyle = UITableViewCellSelectionStyleNone;
		
		UIImageView *imgView = (UIImageView *)[cell viewWithTag:111];
		if(imgView == nil)
		{
			imgView = [[UIImageView alloc] initWithFrame:CGRectMake(HO_HORIZONAL_PADDING, HO_HORIZONAL_PADDING, 48, 48)];
			//			imgView.layer.borderWidth = 1;
			[cell.contentView addSubview:imgView];
			imgView.tag = 111;
		}
		NSURL *imgURL = [NSURL URLWithString:[HOUtils getValideString:entity.image]];
		[imgView sd_setImageWithURL:imgURL placeholderImage:[UIImage imageNamed:@"morentu"]];
		
		UIImageView *urgentImgView = (UIImageView *)[cell viewWithTag:141];
		if(urgentImgView == nil)
		{
			urgentImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 48, 48)];
			//			imgView.layer.borderWidth = 1;
			[cell.contentView addSubview:urgentImgView];
			urgentImgView.tag = 141;
			urgentImgView.image = [UIImage imageNamed:@"icon_urgent"];
		}
		urgentImgView.hidden = !entity.isUrgent;
		
		
		UILabel *statusLbl = (UILabel *)[cell viewWithTag:113];
		if(statusLbl == nil)
		{
			statusLbl = [[UILabel alloc] initWithFrame:CGRectMake(HO_HORIZONAL_PADDING * 2 + imgView.frame.size.width,
																  HO_HORIZONAL_PADDING,
																  tableView.frame.size.width - 58 - 120,
																  22)];
			//			statusLbl.layer.borderWidth = 1;
			statusLbl.textColor = TEXT_COLOR_666666;
			statusLbl.font = [UIFont systemFontOfSize:15];
			[cell.contentView addSubview:statusLbl];
			statusLbl.tag = 113;
		}
		statusLbl.attributedText = [HOUtils getAttributedStringWithTitle:@"状态:" withContent:[entity getStatusStr] withColor:[HOUtils getOrderColorWithStatus:entity.status]];
		
		
		UILabel *orderIdLbl = (UILabel *)[cell viewWithTag:112];
		if(orderIdLbl == nil)
		{
			orderIdLbl = [[UILabel alloc] initWithFrame:CGRectMake(statusLbl.frame.origin.x,
																   statusLbl.frame.origin.y + statusLbl.frame.size.height + 4,
																   tableView.frame.size.width - imgView.frame.size.width - 3 * HO_HORIZONAL_PADDING,
																   22)];
			//			orderIdLbl.layer.borderWidth = 1;
			orderIdLbl.textColor = TEXT_COLOR_666666;
			orderIdLbl.font = [UIFont systemFontOfSize:12];
			[cell.contentView addSubview:orderIdLbl];
			orderIdLbl.tag = 112;
		}
		
		
		orderIdLbl.attributedText = [HOUtils getAttributedStringWithTitle:@"单号:" withContent:[NSString stringWithFormat:@"%d", entity.orderSN] withColor:nil];
		
		
		UILabel *timeLbl = (UILabel *)[cell viewWithTag:114];
		if(timeLbl == nil)
		{
			timeLbl = [[UILabel alloc] initWithFrame:CGRectMake(tableView.frame.size.width - 120,
																HO_HORIZONAL_PADDING,
																110,
																22)];
			//			timeLbl.layer.borderWidth = 1;
			timeLbl.textColor = TEXT_COLOR_666666;
			timeLbl.textAlignment = NSTextAlignmentRight;
			timeLbl.font = [UIFont systemFontOfSize:12];
			[cell.contentView addSubview:timeLbl];
			timeLbl.tag = 114;
		}
		timeLbl.text = [HOUtils getDateFromTimeInterval:entity.createTime * 1000];
		
		
		
		UILabel *locationLbl = (UILabel *)[cell viewWithTag:115];
		if(locationLbl == nil)
		{
			locationLbl = [[UILabel alloc] initWithFrame:CGRectMake(orderIdLbl.frame.origin.x,
																	orderIdLbl.frame.origin.y + orderIdLbl.frame.size.height + 6,
																	tableView.frame.size.width - imgView.frame.size.width - 3 * HO_HORIZONAL_PADDING,
																	22)];
			//			locationLbl.layer.borderWidth = 1;
			locationLbl.textColor = TEXT_COLOR_666666;
			locationLbl.font = [UIFont systemFontOfSize:12];
			[cell.contentView addSubview:locationLbl];
			locationLbl.numberOfLines = 2;
			
			locationLbl.tag = 115;
		}
		locationLbl.attributedText = [HOUtils getAttributedStringWithTitle:@"故障位置:" withContent:entity.address withColor:nil];
		
		[locationLbl sizeToFit];
		
		UILabel *contentLbl = (UILabel *)[cell viewWithTag:116];
		if(contentLbl == nil)
		{
			contentLbl = [[UILabel alloc] initWithFrame:CGRectMake(locationLbl.frame.origin.x,
																   locationLbl.frame.origin.y + locationLbl.frame.size.height + 4,
																   tableView.frame.size.width - imgView.frame.size.width - 3 * HO_HORIZONAL_PADDING,
																   22)];
			//			contentLbl.layer.borderWidth = 1;
			contentLbl.textColor = TEXT_COLOR_666666;
			contentLbl.font = [UIFont systemFontOfSize:14];
			contentLbl.numberOfLines = 2;
			[cell.contentView addSubview:contentLbl];
			contentLbl.textColor = [UIColor blackColor];
			contentLbl.tag = 116;
		}
		if([entity getFaultDetailContent].length > 0)
		{
			contentLbl.attributedText = [HOUtils getAttributedStringWithTitle:@"故障描述:" withContent:[entity getFaultDetailContent]  withColor:nil];
		}
		else
		{
			contentLbl.attributedText = [HOUtils getAttributedStringWithTitle:@"" withContent:[entity getFaultDetailContent]  withColor:nil];
		}
		[contentLbl sizeToFit];
		return cell;
	}
	else if(indexPath.row == 1)
	{
		static NSString *HOReportListTableViewCell = @"HOReportListTableViewCell";
		UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:HOReportListTableViewCell];
		if(cell == nil)
		{
			cell = [[[UITableViewCell alloc]
					 initWithStyle:UITableViewCellStyleDefault
					 reuseIdentifier: HOReportListTableViewCell] autorelease];
		}
		cell.selectionStyle = UITableViewCellSelectionStyleNone;
		
		//		HOButton *takeReportBtn = (HOButton *)[cell viewWithTag:126];
		//		if(takeReportBtn == nil)
		//		{
		//			takeReportBtn = [[[HOButton alloc]
		//						   initWithFrame:CGRectMake(HO_HORIZONAL_PADDING,
		//													7,
		//													80,
		//													30)] autorelease];
		//
		//			takeReportBtn.tag = 126;
		//			[takeReportBtn setTitle:NSLocalizedString(@"接单", @"接单") forState:UIControlStateNormal];
		//			takeReportBtn.layer.borderWidth = [HOUtils defaultOnePixelConversion];
		//			takeReportBtn.layer.borderColor = TEXT_COLOR_009BD3.CGColor;
		//			[takeReportBtn setTitleColor:MAIN_COLOR_NORMAL forState:UIControlStateNormal];
		//			[takeReportBtn setBackgroundImage:[HOUtils createImageWithColor:UIColorFromRGB(0xcccccc) forView:takeReportBtn] forState:UIControlStateSelected];
		//			[takeReportBtn setBackgroundImage:[HOUtils createImageWithColor:UIColorFromRGB(0xcccccc) forView:takeReportBtn] forState:UIControlStateHighlighted];
		//			takeReportBtn.layer.cornerRadius = 5;
		//			[takeReportBtn addTarget:self action:@selector(takeReport:) forControlEvents:UIControlEventTouchUpInside];
		//			takeReportBtn.titleLabel.font = [UIFont systemFontOfSize:13];
		//			[cell.contentView addSubview:takeReportBtn];
		//		}
		//		takeReportBtn = (HOButton *)[cell viewWithTag:126];
		//		takeReportBtn.data = entity;
		//
		//		if( [[[HOStaticDataMgr sharedInstance] getUserInfo] isRepairUser]
		//		   &&  [[[HOStaticDataMgr sharedInstance] getUserInfo] getUserId] != entity.doneId
		//		   && (entity.status == HO_REPORT_ORDER_UNACCEPT))
		//		{
		//			takeReportBtn.hidden = NO;
		//		}
		//		else
		//		{
		//			takeReportBtn.hidden = YES;
		//		}
		
		
		HOButton *confirmBtn = (HOButton *)[cell viewWithTag:116];
		if(confirmBtn == nil)
		{
			confirmBtn = [[[HOButton alloc]
						   initWithFrame:CGRectMake([HOUtils getScreenWidth] - 80 * 2 - HO_HORIZONAL_PADDING * 2,
													7,
													80,
													30)] autorelease];
			
			confirmBtn.tag = 116;
			[confirmBtn setTitle:NSLocalizedString(@"确认完成", @"确认完成") forState:UIControlStateNormal];
			confirmBtn.layer.borderWidth = [HOUtils defaultOnePixelConversion];
			confirmBtn.layer.borderColor = TEXT_COLOR_009BD3.CGColor;
			[confirmBtn setTitleColor:MAIN_COLOR_NORMAL forState:UIControlStateNormal];
			[confirmBtn setBackgroundImage:[HOUtils createImageWithColor:UIColorFromRGB(0xcccccc) forView:confirmBtn] forState:UIControlStateSelected];
			[confirmBtn setBackgroundImage:[HOUtils createImageWithColor:UIColorFromRGB(0xcccccc) forView:confirmBtn] forState:UIControlStateHighlighted];
			confirmBtn.layer.cornerRadius = 5;
			[confirmBtn addTarget:self action:@selector(confirm:) forControlEvents:UIControlEventTouchUpInside];
			confirmBtn.titleLabel.font = [UIFont systemFontOfSize:13];
			[cell.contentView addSubview:confirmBtn];
		}
		confirmBtn = (HOButton *)[cell viewWithTag:116];
		confirmBtn.data = entity;
		int myUserId =  [[[HOStaticDataMgr sharedInstance] getUserInfo] getUserId];
		if(entity.status == HO_REPORT_ORDER_ACCEPTED
		   && [[[HOStaticDataMgr sharedInstance] getUserInfo] isRepairUser]
		   && entity.doneId == myUserId)
		{
			[confirmBtn setTitle:NSLocalizedString(@"维修完成", @"维修完成") forState:UIControlStateNormal];
			confirmBtn.hidden = NO;
		}
		else if(entity.status == HO_REPORT_ORDER_REPAIRED && entity.postId == myUserId)
		{
			[confirmBtn setTitle:NSLocalizedString(@"确认完成", @"确认完成") forState:UIControlStateNormal];
			confirmBtn.hidden = NO;
		}
		else
		{
			confirmBtn.hidden = YES;
		}
		
		HOButton *viewStatusBtn = (HOButton *)[cell viewWithTag:115];
		if(viewStatusBtn == nil)
		{
			
			viewStatusBtn = [[[HOButton alloc]
							  initWithFrame:CGRectMake([HOUtils getScreenWidth] - 80 - HO_HORIZONAL_PADDING,
													   7,
													   80,
													   30)] autorelease];
			
			
			[viewStatusBtn setTitle:NSLocalizedString(@"查看进度", @"查看进度") forState:UIControlStateNormal];
			
			viewStatusBtn.layer.borderWidth = [HOUtils defaultOnePixelConversion];
			viewStatusBtn.layer.borderColor = TEXT_COLOR_666666.CGColor;
			viewStatusBtn.titleLabel.font = [UIFont systemFontOfSize:13];
			viewStatusBtn.layer.cornerRadius = 5;
			viewStatusBtn.tag = 115;
			[viewStatusBtn setTitleColor:TEXT_COLOR_666666 forState:UIControlStateNormal];
			[viewStatusBtn setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
			[viewStatusBtn setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
			[viewStatusBtn addTarget:self action:@selector(viewStatus:) forControlEvents:UIControlEventTouchUpInside];
			[cell.contentView addSubview:viewStatusBtn];
		}
		viewStatusBtn = (HOButton *)[cell viewWithTag:115];
		viewStatusBtn.data = entity;
		return cell;
	}
	return nil;
}

- (void)confirm:(HOButton *)sender
{
	HOReportOrderEntity *orderEntity = (HOReportOrderEntity *)sender.data;
	int myUserId =  [[[HOStaticDataMgr sharedInstance] getUserInfo] getUserId];
	if(orderEntity.status == HO_REPORT_ORDER_ACCEPTED && [[[HOStaticDataMgr sharedInstance] getUserInfo] isRepairUser])
	{
		HORepaireDoneViewController *viewCtrl = [[HORepaireDoneViewController alloc] init];
		viewCtrl.orderId = orderEntity.orderId;
		viewCtrl.isAssistantReport = self.isAssistantReport;
		[self.navigationController pushViewController:viewCtrl animated:YES];
		[viewCtrl release];
	}
	else if(orderEntity.status == HO_REPORT_ORDER_REPAIRED && orderEntity.postId == myUserId)
	{
		if(orderEntity.doneId == 0)
		{
			[self popupHintView:NSLocalizedString(@"此报修单还未维修完成，暂不能确认完成", @"此报修单还未维修完成，暂不能确认完成")];
			return;
		}
		
		HOConfirmOrderViewController *viewCtrl = [[HOConfirmOrderViewController alloc] init];
		viewCtrl.orderEntity = orderEntity;
		[self.navigationController pushViewController:viewCtrl animated:YES];
		[viewCtrl release];
	}
}

- (void)viewStatus:(HOButton *)sender
{
	HOViewStatusViewController *viewCtrl = [[HOViewStatusViewController alloc] init];
	viewCtrl.orderEntity = sender.data;
	[self.navigationController pushViewController:viewCtrl animated:YES];
	[viewCtrl release];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
	HOReportDetailViewController *viewCtrl = [[HOReportDetailViewController alloc] init];
	if(self.isAssistantReport)
	{
		viewCtrl.reportType = HO_REPORT_TYPE_ASSISTANT;
	}
	else
	{
		viewCtrl.reportType = HO_REPORT_TYPE_NORMAL;
	}
	viewCtrl.isFromAssistantList = self.isAssistantReport;
	HOReportOrderEntity *entity = [self.tableViewDataList objectAtIndex:indexPath.section];
	viewCtrl.orderEntity = entity;
	[self.navigationController pushViewController:viewCtrl animated:YES];
	[viewCtrl release];
    
}
#pragma mark - -- tool
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)didReceiveCommand:(NSString *)action data:(id)data
{
	if([action isEqualToString:kHO_CMD_Report_List_Changed])
	{
		[self requestDataWithMaxId:1];
	}
}

- (void)requestDidSuccessWithResponse:(HOBaseResponseEntity *)response
{
	if([response isEqualAction:kHO_ACTION_GetOrderList]
	   || [response isEqualAction:kHO_ACTION_GetSelfAssistantOrderList])
	{
		
		HO_REPORT_ORDER_STATUS requestOrderStatus = [[response.baseRequest.params objectForKey:kHO_FIELD_Status] intValue];
		if(self.currentStatus != requestOrderStatus)
		{
			return;
		}
		
		[self.tableViewDataList removeAllObjects];
		[reportDic removeAllObjects];
		[baseTableview clearsContextBeforeDrawing];
		for(int i = 0; i < [response.dataNode count]; i ++)
		{
			NSDictionary *dic = [response.dataNode objectAtIndex:i];
			int orderId = [[dic objectForKey:kHO_FIELD_OrderId] intValue];
			HOReportOrderEntity *entity = [reportDic objectForKey:[NSNumber numberWithInt:orderId]];
			if(entity == nil)
			{
				entity = [[[HOReportOrderEntity alloc] init] autorelease];
				[reportDic setObject:entity forKey:[NSNumber numberWithInt:orderId]];
				[self.tableViewDataList addObject:entity];
			}
			
			[entity parseDic:dic];
		}
		[self doneLoadingTableViewRefresh];
	}
}

- (void)dealloc
{
	[reportDic release];
	[super dealloc];
}

@end
